package com.park.user.controller.user;

import com.park.controller.BaseController;
import com.park.entity.user.UserLoginVo;
import com.park.entity.wx.WxEncryptedDataParam;
import com.park.entity.wx.WxLoginParam;
import com.park.entity.wx.WxUserInfoParam;
import com.park.response.Result;
import com.park.user.anno.UserToken;
import com.park.user.service.user.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author Administrator
 * @title: UserController
 * @projectName park
 * @description: 用户控制器
 * @date 2020/5/28:59
 */
@RestController
@RequestMapping(value = "/wx/userinfo")
public class UserController extends BaseController {

    @Autowired
    private UserService userService;

    /* *
     * @Author zhanghaiwen
     * @Description 获取用户AccessToken
     * @Date 14:16 2020/1/8
     * @Param [User]
     * @Version 6.1.1
     * @return
     */
    @RequestMapping(value = "/accesstoken",method = RequestMethod.POST)
    public Result getAccessToken(){
        return SUCCESS();
    }

    /* *
     * @Author zhanghaiwen
     * @Description 用户登录
     * @Date 14:16 2020/1/8
     * @Param [User]
     * @Version 6.1.1
     * @return
     */
    @RequestMapping(value = "/login",method = RequestMethod.POST)
    public Result userLogin(@RequestBody WxLoginParam wxLoginParam){
        UserLoginVo userLoginVo = userService.login(wxLoginParam);
        return SUCCESS(userLoginVo);
    }

    /* *
     * @Author zhanghaiwen
     * @Description 获取用户手机号码
     * @Date 14:16 2020/1/8
     * @Param [User]
     * @Version 6.1.1
     * @return
     */
    @UserToken
    @RequestMapping(value = "/get/phoneNumber",method = RequestMethod.POST)
    public Result getPhoneNumber(@RequestBody WxEncryptedDataParam wxEncryptedDataParam){
        Integer userId = getUserId();
        wxEncryptedDataParam.setUserId(userId);
        userService.getPhoneNumber(wxEncryptedDataParam);
        return SUCCESS();
    }

    /* *
     * @Author zhanghaiwen
     * @Description 获取用户基本信息
     * @Date 14:16 2020/1/8
     * @Param [User]
     * @Version 6.1.1
     * @return
     */
    @UserToken
    @RequestMapping(value = "/get/userinfo",method = RequestMethod.POST)
    public Result getUserInfo(@RequestBody WxUserInfoParam wxUserInfoParam){
        Integer userId = getUserId();
        wxUserInfoParam.setUserId(userId);
        userService.getUserInfo(wxUserInfoParam);
        return SUCCESS();
    }

}
